package com.oss.biz;

import cn.hutool.core.lang.Validator;
import com.eova.common.base.BaseController;
import com.jfinal.aop.Before;
import com.oss.intercept.jwt.LoginInterceptor;
import com.oss.service.OrderService;
import com.oss.utils.BaseContextHandler;
import com.oss.view.InvokeResult;

public class OrderController extends BaseController {

    static OrderService orderService = new OrderService();


    /**
     * 判断订单是否正常
     */
//    @Before(LoginInterceptor.class)
    public void isAbnormal() {
        String employeeId = BaseContextHandler.getUserID();
        if (Validator.isEmpty(employeeId)) {
            employeeId = "1";
        }
        String memberCode = this.getPara("memberCode");
        renderJson(orderService.isAbnormal(employeeId, memberCode));
    }

    /**
     * 分页查询店员核销订单
     */
//    @Before(LoginInterceptor.class)
    public void queryOrderListByEmployee() {
        String employeeId = BaseContextHandler.getUserID();
        if (Validator.isEmpty(employeeId)) {
            employeeId = "1";
        }
        Integer pageNumber = this.getParaToInt("pageNumber", 1);
        Integer pageSize = this.getParaToInt("pageSize", 10);

        String start = this.getPara("start");
        String end = this.getPara("end");

        renderJson(orderService.queryOrderListByEmployee(pageNumber, pageSize, employeeId, start, end));
    }

    /**
     * 扫码记录订单
     */
    @Before(LoginInterceptor.class)
    public void addOrder() {
        String memberCode = this.getPara("memberCode");
        String seriesId = this.getPara("seriesId");
        String employeeId = BaseContextHandler.getUserID();

        if (Validator.isNotEmpty(employeeId) && seriesId.equals("undefined")) {
            renderJson(InvokeResult.failure("请先选择系列"));
            return;
        }
//        if (Validator.isEmpty(employeeId)) {
//            employeeId = "1";
//        }
        renderJson(orderService.addOrder(memberCode, employeeId, Integer.valueOf(seriesId)));
    }


}
